package com.zhangmengyuan.medical.controller;

import com.zhangmengyuan.medical.entity.Order;
import com.zhangmengyuan.medical.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    public String save(Order order, Model model){
        this.orderService.save(order);
        return "redirect:order/all";

    }
    public String update(Order order, @PathVariable("orderId") Integer orderId, Model model)/*路径传参*/
    {/*Intger代表类型，代表这个id必须是整数*/
        order.setOrderId(orderId);
        this.orderService.save(order);
        return "redirect:/order/all";
    }

    public String getOrder(Model model) {
        List<Order> orderList = this.orderService.getAll();/*页面传参*/
   /* 在 JSP 视图页面中通过 request.getAttribute(“customerList”)
   或者通过 ${customerList} EL 表达式访问模型对象中的 customerList对象*/
        model.addAttribute("orderList", orderList);
        return "showinfo";/*在方法上直接return一个字符串，就会对应webapp/WEB-INF.jsp/下的文件，不需要index.jsp*/
    }

    public String getOrderById(@PathVariable("orderId") Integer orderId, Model model) {
        Order order = this.orderService.getById(orderId);
        model.addAttribute("order", order);
        return "redirect:/showinfo";
    }

  /*@GetMapping("/delete/{userId}")
  public String deleteUserById(@PathVariable("userId") Integer userId,Model model){
    User user = this.userService.getById(userId);
    this.userService.deleteUserById(user);
    return "detil";

  }*/


    public String toDetil(Model model) {
        return "showinfo";
    }

}
